import pymysql

def create_obj():
    db = pymysql.connect("localhost", "root", "", "woniu_book", charset='utf8')
    cur = db.cursor()
    return db,cur
# 针对增删改操作
def db_operation(sql):
    db,cur=create_obj()
    cur.execute(sql)
    db.commit()
    cur.close()
    db.close()
# 针对查询一条语句
def db_queryone(sql):
    db, cur = create_obj()
    cur.execute(sql)
    db.commit()
    result=cur.fetchone()
    cur.close()
    db.close()
    return result
#针对查询所有结果
def db_queryall(sql):
    db, cur = create_obj()
    cur.execute(sql)
    db.commit()
    result=cur.fetchall()
    cur.close()
    db.close()
    return result

